package greedy;

/**
 * Created with IntelliJ IDEA.
 * Description: 860. 柠檬水找零
 * User: Li_yizYa
 * Date: 2025/6/26
 * Time: 16:39
 */
public class Solution10 {
    public boolean lemonadeChange(int[] bills) {
        if (bills == null || bills.length == 0) {
            return false;
        }
        int five = 0;
        int ten = 0;
        for (int bill : bills) {
            if (bill == 5) {
                five++;
            }
            if (bill == 10) {
                ten++;
                if (five == 0) {
                    return false;
                }
                five--;
            }
            if (bill == 20) {
                if (five > 0 && ten > 0) {
                    ten--;
                    five--;
                } else if (five >= 3) {
                    five -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}
